package org.usmile.algorithms.huawei.acm;

import java.util.Scanner;

// https://blog.csdn.net/amos_cloud/article/details/129350087
public class _递增字符串 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int bCount = 0;
        int min = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == 'B') {
                bCount++;
            } else {
                // 将之前的B全部改为A或者将此A改为B
                min = Math.min(min + 1, bCount);
            }
        }

        System.out.println(min);
    }
}
